package com.gitee.wsl.jvm.okhttp.intercept.base

import okhttp3.Headers
import okhttp3.Interceptor
import okhttp3.Response
import java.io.IOException


/**
 * 配置公共头部
 *
 */
class HeadersInterceptor(val headers: Headers) : Interceptor {

    @Throws(IOException::class)
    override fun intercept(chain: Interceptor.Chain): Response {
        val builder = chain.request().newBuilder()
        if (headers.size==0) {
            return chain.proceed(builder.build())
        }
        headers.forEach { (key, value) ->
            builder.addHeader(key,value)
        }
        return chain.proceed(builder.build())
    }
}